home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / GNUUCP_2 / SOURCE / PROTOCOL.DOC < prev    next >
Text File  |  1989-07-31  |  27KB  |  1,006 lines

  1. Return-Path: gnu
  2. Return-Path: <gnu>
  3. Received: by hoptoad.uucp (1.1/SMI-3.0DEV3)
  4.     id AA08407; Fri, 14 Nov 86 14:39:57 PST
  5. Date: Fri, 14 Nov 86 14:39:57 PST
  6. From: gnu (John Gilmore)
  7. Message-Id: <8611142239.AA08407@hoptoad.uucp>
  8. To: ihnp4!nucsrl!naim (Naim Abdullah)
  9. Subject: Here is a description of the uucp protocols
  10.  
  11. There is a collection of people interested in writing a version
  12. of uucp in the public domain.  Contact ihnp4!akgua!ucf-cs!ki4pv!tanner
  13. to be added to the mailing list.  There have only been three messages
  14. sent to the list -- one was trivia, the other two are below.
  15.  
  16.     John Gilmore
  17.  
  18. From: ihnp4!akgua!ucf-cs!ki4pv!tanner
  19. To: ucf-cs!ki4pv-uucpinfo2, ucf-cs!ki4pv-uucpinfo1
  20. Subject: UUCP Information Issue #02
  21. Date: Wed Dec 11 23:39:26 1985
  22.  
  23. This is the second issue; the information below is the start of
  24. what has been collected here.  It is expected that more information
  25. will be collected in the next few weeks, and that information will
  26. be forwarded when/if it becomes available.
  27.  
  28.  =====================================================
  29.  -- part 1
  30.  =====================================================
  31. This information came via several people, most of whom snet this
  32. exact message (probably from their news archives from before we
  33. joined the net):
  34.  
  35.     I am posting this over the network because I believe that
  36.     others are interested in knowing the protocols of UUCP.
  37.     Below is listed all the information that I have acquired
  38.     to date. This includes the initial handshaking phase, though
  39.     not the login phase. It also doesn't include information
  40.     about the data transfer protocol for non-packet networks
  41.     (the -G option left off the uucico command line). But, just
  42.     hold on - I am working on that stuff.
  43.  
  44.     For a point of information : the slave is the UUCP site being
  45.     dialed, and the master is the one doing the calling up. The
  46.     protocols listed in the handshaking and termination phase are
  47.     independent of any UUCP site : it is universal. The stuff in
  48.     the work phase depends on the specific protocol chosen. The
  49.     concepts in the work phase are independent of protocol, ie. the
  50.     sequences are the same. It is just the lower level stuff that
  51.     changes from protocol to protocol. I have access only to level
  52.     g and will document it as I begin to understand it.
  53.  
  54.     Most of the stuff you see here is gotten from the debug phase
  55.     of the current BSD UUCP system.
  56.  
  57.     I hope this is useful. Maybe this will get some of the real
  58.     'brains' in UUCP to get off their duffs and provide some real
  59.     detail. In any case, if you have any questions please feel
  60.     free to contact me. I will post any questions and answers over
  61.     the network.
  62.  
  63.  
  64.                 Chuck Wegrzyn
  65.                 {allegra,decvax,ihnp4}!encore!wegrzyn
  66.  
  67.                 (617) 237-1022
  68.  
  69.  
  70.  
  71.             UUCP Handshake Phase
  72.             ====================
  73.  
  74. Master                            Slave
  75. ------                            -----
  76.  
  77.                     <-----        \020Shere\0     (1)
  78.  
  79.  
  80. (2)  \020S<mastername> <switches>\0    ----->
  81.  
  82.  
  83.                     <-----        \020RLCK\0      (3)
  84.                             \020RCB\0
  85.                             \020ROK\0
  86.                             \020RBADSEQ\0
  87.  
  88.                     <-----        \020P<protos>\0 (4)
  89.  
  90.  
  91. (5) \020U<proto>\0            ----->
  92.     \020UN\0
  93.  
  94.  
  95. (6) ...
  96.  
  97.  
  98. (0) This communication happens outside of the packet communication that
  99.     is supported. If the -G flag is sent on the uucico line, all
  100.     communications will occur without the use of the packet
  101.     simulation software. The communication at this level is just
  102.     the characters listed above.
  103.  
  104. (1) The slave sends the sequence indicated, while the master waits for
  105.     the message.
  106.  
  107. (2) The slave waits for the master to send a response message. The message
  108.     is composed of the master's name and some optional switches.
  109.     The switch field can include the following
  110.  
  111.             -g        (set by the -G switch on the
  112.                      master's uucico command line.
  113.                      Indicates that communication
  114.                      occurs over a packet switch net.)
  115.             -xN        (set by the -x switch on the
  116.                      master's uucico command line.
  117.                      The number N is the debug level
  118.                      desired.)
  119.             -QM        (M is really a sequence number
  120.                      for the communication.)
  121.  
  122.     Each switch is separated from the others by a 'blank' character.
  123.  
  124. (3) The slave will send one of the many responses. The meanings appear to
  125.     be :
  126.  
  127.     RLCK
  128.  
  129.         This message implies that a 'lock' failure occurred:
  130.         a file called LCK..mastername couldn't be created since
  131.         one already exists. This seems to imply that the master
  132.         is already in communication with the slave.
  133.  
  134.     RCB
  135.  
  136.         This message will be sent out if the slave requires a
  137.         call back to the master - the slave will not accept a
  138.         call from the master but will call the master instead.
  139.  
  140.     ROK
  141.  
  142.         This message will be returned if the sequence number that
  143.         was sent in the message, attached to the -Q switch, from 
  144.         the master is the same as that computed on the slave.
  145.  
  146.     RBADSEQ
  147.  
  148.         Happens if the sequence numbers do not match.
  149.  
  150.     (Notes on the sequence number - if a machine does not keep
  151.      sequence numbers, the value is set to 0. If no -Q switch
  152.      is given in the master's line, the sequence number is
  153.      defaulted to 0.
  154.  
  155.      The sequence file, SQFILE, has the format
  156.  
  157.         <remotename> <number> <month>/<day>-<hour>:<min>
  158.  
  159.      where <remotename> is the name of a master and <number>
  160.      is the previous sequence number. If the <number> field
  161.      is not present, or if it is greater than 9998, it is
  162.      set to 0. The <number> field is an ascii representation
  163.      of the number. The stuff after the <number> is the time
  164.      the sequence number was last changed, this information
  165.      doesn't seem important.)
  166.  
  167. (4) The slave sends a message that identifies all the protocols that
  168.     it supports. It seems that BSD supports 'g' as the normal case.
  169.     Some sites, such as Allegra, support 'e' and 'g', and a few
  170.     sites support 'f' as well. I have no information about these
  171.     protocols. The exact message sent might look like
  172.  
  173.         \020Pefg\0
  174.  
  175.     where efg indicates that this slave supports the e,f and g 
  176.     protocols.
  177.  
  178. (5) The slave waits for a response from the master with the chosen
  179.     protocol. If the master has a protocol that is in common the
  180.     master will send the message
  181.  
  182.         \020U<proto>\0
  183.  
  184.     where <proto> is the protocol (letter) chosen. If no protocol
  185.     is in common, the master will send the message
  186.  
  187.         \020UN\0
  188.  
  189. (6) At this point both the slave and master agree to use the designated
  190.     protocol. The first thing that now happens is that the master
  191.     checks for work.
  192.  
  193. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  194.  
  195.             UUCP Work Phase
  196.             ===============
  197.  
  198.  
  199. Master                            Slave
  200. ------                            -----
  201.  
  202. (a) Master has UUCP Work
  203.  
  204.     (1) X file1 file2     ----->
  205.  
  206.                     <-----        XN        (2)
  207.                             XY
  208.  
  209.     When the master wants the slave to do a 'uux' command
  210.     it sends the X message. If the slave can't or won't
  211.     do it, the slave will send an XN message. Otherwise
  212.     it will send an XY message.
  213.  
  214. (b) Master wants to send a file
  215.  
  216.     (1) S file1 file2 user options  ----->
  217.  
  218.                     <-----        SN2        (2)
  219.                             SN4
  220.                             SY
  221.  
  222.             <---- <data exchanged>---->            (3)
  223.  
  224.  
  225.                     <-----        CY        (4)
  226.                             CN5
  227.  
  228.     If the master wishes to send a file to the slave, it will
  229.     send a S message to the slave. If the slave can or will do
  230.     the transfer, it sends a SY message. If the slave has a
  231.     problem creating work files, it sends a SN4 message. If
  232.     the target file can't be created (because of priv's etc)
  233.     it sends a SN2 message.
  234.  
  235.     The file1 argument is the source file, and file2 is the
  236.     (almost) target filename. If file2 is a directory, then
  237.     the target filename is composed of file2 concatenated
  238.     with the "last" part of the file1 argument. Note, if the
  239.     file2 argument begins with X, the request is targeted to
  240.     UUX and not the normal send.
  241.  
  242.     The user argument indicates who, if anyone, is to be notified
  243.     if the file has been copied. This user must be on the slave
  244.     system.
  245.  
  246.     I am not sure what the options argument does.
  247.  
  248.     After the data has been exchanged the slave will send one of
  249.     two messages to the master. A CY message indicates that every-
  250.     thing is ok. The message CN5 indicates that the slave had
  251.     some problem moving the file to it's permanent location. This
  252.     is not the same as a problem during the exchange of data : this
  253.     causes the slave to terminate operation.
  254.  
  255. (c) Master wishes to receive a file.
  256.  
  257.     (1) R file1 file2 user    ----->
  258.  
  259.                         <-----    RN2        (2)
  260.                             RY mode
  261.  
  262.     (3)        <---- <data exchanged> ---->
  263.  
  264.     (4)    CY        ----->
  265.         CN5
  266.  
  267.     If the master wishes the slave to send a file, the master sends
  268.     a R message. If the slave has the file and can send it, the
  269.     slave will respond with the RY message. If the slave can't find
  270.     the file, or won't send it the RN2 message is sent. It doesn't
  271.     appear that the 'mode' field of the RY message is used.
  272.  
  273.     The argument file1 is the file to transfer, unless it is a
  274.     directory. In this case the file to be transferred is built
  275.     of a concatenation of file1 with the "last" part of the file2
  276.     argument.
  277.  
  278.     If anything goes wrong with the data transfer, it results in
  279.     both the slave and the master terminating.
  280.  
  281.     After the data has been transferred, the master will send an
  282.     acknowledgement to the slave. If the transfer and copy to the
  283.     destination file has been successful, the master will send the
  284.     CY message. Otherwise it will send the CN5 message.
  285.  
  286. (d) Master has no work, or no more work.
  287.  
  288.     (1) H            ----->
  289.  
  290.                 <-----                HY    (2)
  291.                                 HN
  292.  
  293.     (3) HY            ----->
  294.  
  295.                 <----                HY    (4)
  296.  
  297.     (5) ...
  298.  
  299.     The transfer of control is initiated with the master sending
  300.     a H message. This message tells the slave that the master has
  301.     no work, and the slave should look for work.
  302.  
  303.     If the slave has no work it will respond with the HY message.
  304.     This will tell the master to send an HY message, and turn off
  305.     the selected protocol. When the HY message is received by the
  306.     slave, it turns off the selected protocol as well. Both the
  307.     master and slave enter the UUCP termination phase.
  308.  
  309.     If the slave does have work, it sends the HN message to the
  310.     master. At this point, the slave becomes the master. After
  311.     the master receives the HN message, it becomes the slave.
  312.     The whole sequence of sending work starts over again. Note,
  313.     the transmission of HN doesn't force the master to send any
  314.     other H messages : it waits for stuff  from the new master.
  315.  
  316. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  317.  
  318.  
  319.             UUCP Termination Sequence
  320.             =========================
  321.  
  322.  Master                                Slave
  323.  ------                                -----
  324.  
  325.  (1) \020OOOOOO\0        ----->
  326.  
  327.                 <-----            \020OOOOOOO\0 (2)
  328.  
  329.  
  330.  
  331.     At this point all conversation has completed normally.
  332.  
  333.  
  334. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  335.  
  336.             UUCP Data Transfers
  337.             ===================
  338.  
  339.     After the initial handshake the systems send messages in one
  340.     of two styles : packet and not packet. A Packet protocol is
  341.     just raw data transfers : there is no protocol or acknowledgements;
  342.     this appears to assume that the lower level is a packet network
  343.     of some type. If the style is not Packet, then extra work is
  344.     done. I am still working on this stuff.
  345.  
  346.  =====================================================
  347.  -- part 2
  348.  =====================================================
  349.  ** summary of UUCP packets ** 
  350. (this is much like part 1, but shortened and compared against a
  351. live UUCP ~uucp_adm/uucico)
  352.  
  353. note that all transmissions end with a null, not shown here
  354.  
  355.  
  356. (master)        (slave)
  357.  
  358.  ... dials up ...    <DLE>Shere        says "hello"
  359.  
  360. <DLE>S<sysname> <opts>                says who he is
  361.  
  362.         |    <DLE>ROK        says ok to talk
  363.         |    <DLE>RLCK        says locked out
  364.         |    <DLE>RCB        says will call back
  365.         |    <DLE>RBADSEQ        says bad seq num
  366.  
  367.             <DLE>P<protos>        what protocols he has
  368.  
  369. <DLE>U<proto>    |                which to use
  370. <DLE>UN        |                use none, hang up
  371.  
  372.  
  373. packet driver is turned on at this time, if not told otherwise
  374.  
  375.  -- if master has work --
  376.  
  377. to sned file to slave...
  378. S <mfilenm> <sfilenm> <user> <opts>        request to sned file
  379.  
  380.         |    SY            ok -- i'll take it
  381.         |    SN2            not permitted
  382.         |    SN4            can't make workfile
  383.  
  384. <data>                        the file is transmitted
  385.  
  386.         |    CY            finished OK
  387.         |    CN5            can't move into place
  388.  
  389.  
  390. to recv file from slave...
  391. R <sfilenm> <mfilenm> <user>            request to recv file
  392.  
  393.         |    RY<mode>        ok -- here is prot mode
  394.         |    RN2            not permitted
  395.  
  396.             <data>            file is transmitted
  397.  
  398. CY        |                worked
  399. CN5        |                can't move into place
  400.  
  401.  
  402. to do UUX on slave...
  403. X <file1> <file2>                request to exec file
  404.  
  405.         |    XY            ok -- will do
  406.         |    XN            nopers
  407.  
  408. to indicate that he has no more work...
  409. H                        no more work
  410.  
  411.         |    HN            reverse roles
  412.         |    HY            no work here either
  413.  
  414. to accept slave's claim of no more work...
  415.  
  416. HY                        agrees to hang up
  417.  
  418. the rest of the hang-up is done OUTSIDE of packet driver
  419. <DLE>OOOOOO                    signs off (6*'O')
  420.  
  421.             <DLE>OOOOOOO        signs off (7*'O')
  422.     
  423.  
  424. If the slave has work, then the roles are reversed, and the
  425. session proceeds from the label 'loop1' above.  The system
  426. which was the slave is now the master, and the old master is
  427. just the slave.
  428.  
  429. The <opts> which follow the system name for the start-up sequence
  430. include:
  431.     -g        don't use packet driver (command line -G)
  432.     -xN        debug level (command line -Xn)
  433.     -QN        seq number (if systems use this)
  434.  
  435. The filenames for <mfilenm> should be complete filenames with
  436. path information; otherwise they are assumed to be in /usr/spool/uucp.
  437. The filenames for <sfilenm> should be either complete filenames
  438. or directory names.  If directory names are used, then the final
  439. componant of <mfilenm> is appended to form the complete filename.
  440.  
  441. The 'X' command to do UUX on a slave is more than a little unclear.
  442. It doesn't seem to work here, but that may be a microsoft "feature".
  443.  
  444.  
  445. Protocol "g", which seems to be the one most commonly used, is supposed
  446. to be a slightly munged version of level 2 of X.25; an article was just
  447. posted in net.unix-wizards (which you probably have already seen) to
  448. this effect.  The article didn't provide any details on the protocol,
  449. but merely mentioned the modifications.
  450.  
  451. The "packet" mode, with no protocol, does not work under microsoft
  452. implementations, and may have *lots* of trouble working anywhere
  453. else as well.  It evidently requires that zero-length reads happen
  454. every so often to delimit things, such as files being transferred.
  455. This of course can't happen without the packet driver, which was long
  456. gone by the time sys-3 or sys-5 or <your current version> came along.
  457.  
  458. **********************************
  459. ** end of issue #2
  460. **********************************
  461.  
  462.  
  463. From: ihnp4!akgua!ucf-cs!ki4pv!tanner
  464. Message-Id: <8601130718.AA27631@ucf-cs.UUCP>
  465. To: ucf-cs!ki4pv-uucpinfo, allegra!mp
  466. Subject: UUCP INFO mailing list issue #03
  467. Date: Sun Jan 12 19:11:18 1986
  468.  
  469. The following information, describing the uucp 'g' protocol, was
  470. provided as "nroff" source.  Cut the header and this text off of
  471. the message, and run it through "nroff".
  472. .ce
  473. .B
  474. Packet Driver Protocol
  475. .R
  476. .sp 1
  477. .ce
  478. G. L. Chesson
  479. .br
  480. .ce
  481. Bell Laboratories
  482. .SH
  483. Abstract
  484. .in +.5i
  485. .PP
  486. These notes describe the packet driver link
  487. protocol that was supplied
  488. with the
  489. Seventh Edition of
  490. .UX
  491. and is used by the UUCP program.
  492. .in -.5i
  493. .SH
  494. General
  495. .PP
  496. Information flow between a pair of machines
  497. may be regulated by
  498. first
  499. representing the data 
  500. as sequence-numbered 
  501. .I
  502. packets
  503. .R
  504. of data 
  505. and then establishing conventions that
  506. govern the use of sequence numbers.
  507. The
  508. .I
  509. PK,
  510. .R
  511. or
  512. .I
  513. packet driver,
  514. .R
  515. protocol
  516. is a particular instance of this type of
  517. flow-control discipline.
  518. The technique depends on the notion of a transmission
  519. .I
  520. window
  521. .R
  522. to determine upper and lower bounds for valid
  523. sequence numbers.
  524. The transmitter is allowed to retransmit packets
  525. having sequence numbers
  526. within the window until the receiver indicates that
  527. packets have been correctly received.
  528. Positive acknowledgement from the receiver moves the
  529. window;
  530. negative acknowledgement or no acknowledgement
  531. causes retransmission.
  532. The receiver must ignore duplicate transmission, detect
  533. the various errors that may occur,
  534. and inform the transmitter when packets are 
  535. correctly or incorrectly received.
  536. .PP
  537. The following paragraphs describe the packet formats,
  538. message exchanges,
  539. and framing
  540. used by the protocol as coded
  541. in the UUCP program and the
  542. .UX
  543. kernel.
  544. Although no attempt will be made here to present
  545. internal details of the algorithms that were used,
  546. the checksum routine is supplied
  547. for the benefit of other implementors.
  548. .SH
  549. Packet Formats
  550. .PP
  551. The protocol is defined in terms of message
  552. transmissions of 8-bit bytes.
  553. Each message includes one
  554. .I
  555. control
  556. .R
  557. byte plus a
  558. .I
  559. data segment
  560. .R
  561. of zero or more information bytes.
  562. The allowed data segment sizes range
  563. between 32 and 4096 as determined by the formula
  564. 32(2\uk\d) where
  565. k is a 3-bit number.
  566. The packet sequence numbers are likewise constrained
  567. to 3-bits; i.e. counting proceeds modulo-8.
  568. .PP
  569. The control byte is partitioned into three fields as
  570. depicted below.
  571. .bp
  572. .nf
  573. .sp 
  574. .in 1i
  575. .ls 1
  576. bit    7    6    5    4    3    2    1    0
  577.     t    t    x    x    x    y    y    y
  578. .ls 1
  579. .in -1i
  580. .fi
  581. .sp
  582. The
  583. .I
  584. t
  585. .R
  586. bits indicate a packet type and
  587. determine the interpretation to be placed on
  588. the
  589. .I
  590. xxx
  591. .R
  592. and
  593. .I
  594. yyy
  595. .R
  596. fields.
  597. The various interpretations are as follows:
  598. .in +1i
  599. .sp
  600. .nf
  601. .ls 1
  602. .I
  603. tt    interpretation
  604. .sp
  605. .R
  606. 00    control packet
  607. 10    data packet
  608. 11    `short' data packet
  609. 01    alternate channel
  610. .ls 1
  611. .fi
  612. .sp
  613. .in -1i
  614. A data segment accompanies all non-control packets.
  615. Each transmitter is constrained to observe the maximum
  616. data segment size
  617. established during initial synchronization by the
  618. receiver that it sends to.
  619. Type 10 packets have maximal size data segments.
  620. Type 11, or `short', packets have zero or more data
  621. bytes but less than the maximum.
  622. The first one or two bytes of the data segment of a
  623. short packet are `count' bytes that
  624. indicate the difference between the
  625. maximum size and the number of bytes in the short
  626. segment.
  627. If the difference is less than 127, one count
  628. byte is used.
  629. If the difference exceeds 127,
  630. then the low-order seven bits of the difference
  631. are put in the first data byte and the high-order
  632. bit is set as an indicator that the remaining
  633. bits of the difference are in the second byte.
  634. Type 01 packets are never used by UUCP
  635. and need not be discussed in detail here.
  636. .PP
  637. The sequence number of a non-control packet is
  638. given by the
  639. .I
  640. xxx
  641. .R
  642. field.
  643. Control packets are not sequenced.
  644. The newest sequence number,
  645. excluding duplicate transmissions,
  646. accepted by a receiver is placed in the
  647. .I
  648. yyy
  649. .R
  650. field of non-control packets sent to the
  651. `other' receiver.
  652. .PP
  653. There are no data bytes associated with a control packet,
  654. the
  655. .I
  656. xxx
  657. .R
  658. field is interpreted as a control message,
  659. and the
  660. .I
  661. yyy
  662. .R
  663. field is a value accompanying the control message.
  664. The control messages are listed below in decreasing priority.
  665. That is, if several control messages are to be sent,
  666. the lower-numbered ones are sent first.
  667. .in +1i
  668. .nf
  669. .ls 1
  670. .sp
  671. .I
  672. xxx    name        yyy
  673. .R
  674.  
  675. 1    CLOSE    n/a
  676. 2    RJ        last correctly received sequence number
  677. 3    SRJ        sequence number to retransmit
  678. 4    RR        last correctly received sequence number
  679. 5    INITC    window size
  680. 6    INITB    data segment size
  681. 7    INITA    window size
  682. .in -i
  683. .ls 1
  684. .fi
  685. .sp
  686. .PP
  687. The CLOSE message indicates that the communications channel
  688. is to be shut down.
  689. The RJ, or
  690. .I
  691. reject,
  692. .R
  693. message indicates that the receiver has detected an error
  694. and the sender should retransmit after using the 
  695. .I
  696. yyy
  697. .R
  698. field to update the window.
  699. This mode of retransmission is usually
  700. referred to as a
  701. `go-back-N' procedure.
  702. The SRJ, or
  703. .I
  704. selective reject,
  705. .R
  706. message carries with it the sequence number of
  707. a particular packet to be retransmitted.
  708. The RR, or
  709. .I
  710. receiver ready,
  711. .R
  712. message indicates that the receiver has detected
  713. no errors; the
  714. .I
  715. yyy
  716. .R
  717. field updates the sender's window.
  718. The INITA/B/C messages are used
  719. to set window and data segment sizes.
  720. Segment sizes are calculated by the formula
  721. 32(2\uyyy\d)
  722. as mentioned above,
  723. and window sizes may range between 1 and 7.
  724. .PP
  725. Measurements of the protocol running on communication
  726. links at rates up to 9600 baud showed that
  727. a window size of 2 is optimal
  728. given a packet size greater than 32 bytes.
  729. This means that the link bandwidth can be fully utilized
  730. by the software.
  731. For this reason the SRJ message is not as important as it
  732. might otherwise be.
  733. Therefore the
  734. .UX
  735. implementations no longer generate or respond to SRJ
  736. messages.
  737. It is mentioned here for historical accuracy only,
  738. and one may assume that SRJ is no longer part of the protocol.
  739. .SH
  740. Message Exchanges
  741. .SH
  742.     Initialization
  743. .PP
  744. Messages are exchanged between four cooperating
  745. entities: two senders and two receivers.
  746. This means that the communication channel is thought of
  747. as two independent half-duplex data paths.
  748. For example the window and segment sizes need not
  749. be the same in each direction.
  750. .PP
  751. Initial synchronization is accomplished
  752. with two 3-way handshakes: two each of
  753. INITA/INITB/INITC.
  754. Each sender transmits INITA messages repeatedly.
  755. When an INITA message is received, INITB is
  756. sent in return.
  757. When an INITB message is received
  758. .I
  759. and
  760. .R
  761. an INITB message has been sent,
  762. an INITC message is sent.
  763. The INITA and INITB messages carry 
  764. with them the packet and window size that
  765. each receiver wants to use,
  766. and the senders are supposed to comply.
  767. When a receiver has seen all three
  768. INIT messages, the channel is 
  769. considered to be open.
  770. .PP
  771. It is possible to design a protocol that starts up using
  772. fewer messages than the interlocked handshakes described above.
  773. The advantage of the more complicated design lies in its use as
  774. a research vehicle:
  775. the initial handshake sequence is completely symmetric,
  776. a handshake
  777. can be initiated by one side of the link while the
  778. connection is in use, and the software to do this can
  779. utilize code that would ordinarily be used only once
  780. at connection setup time.
  781. These properties were used in experiments with dynamically
  782. adjusted parameters.
  783. That is attempts were made to adapt the window and segment
  784. sizes to changes observed in traffic while a link was in use.
  785. Other experiments used the initial
  786. handshake  in a different way
  787. for restarting the protocol without data loss
  788. after machine crashes.
  789. These experiments never worked well in the packet driver and
  790. basically provided the impetus for other protocol designs.
  791. The result 
  792. as far as UUCP is concerned is that initial synchronization
  793. uses the two 3-way handshakes, and the INIT
  794. messages are ignored elsewhere.
  795. .SH
  796.     Data Transport
  797. .PP
  798. After initial synchronization each receiver
  799. sets a modulo-8 incrementing counter R to 0;
  800. each sender sets a similar counter S to 1.
  801. The value of R is always the number of the most recent
  802. correctly received packet.
  803. The value of S is always the first sequence number in
  804. the output window.
  805. Let W denote window size.
  806. Note that the value of W may be different for each sender.
  807. .PP
  808. A sender may transmit packets with sequence numbers
  809. in the range S to (S+W-1)\ mod-8.
  810. At any particular time a receiver expects
  811. arriving packets to have numbers in the range
  812. (R+1)\ mod-8 to (R+W)\ mod-8.
  813. Packets must arrive in sequence number order
  814. are are only acknowledged in order.
  815. That is,
  816. the `next' packet a receiver
  817. will acknowledge must have
  818. sequence number (R+1)\ mod-8.
  819. .PP
  820. A receiver acknowledges receipt of data packets
  821. by arranging for the value of its R counter to be
  822. sent across the channel
  823. where it will be used to update an S counter.
  824. This is done in two ways.
  825. If data is flowing in both directions across a
  826. channel then each receiver's current R value is
  827. carried in the
  828. .I
  829. yyy
  830. .R
  831. field of non-control packets.
  832. Otherwise when there is no bidirectional
  833. data flow,
  834. each receiver's R value is transmitted across the link
  835. as the
  836. .I
  837. yyy
  838. .R
  839. field of an RR control packet.
  840. .PP
  841. Error handling is up to the discretion
  842. of the receiver.
  843. It can ignore all errors in which case
  844. transmitter timeouts must provide for
  845. retransmission.
  846. The receiver may also generate RJ 
  847. error control packets.
  848. The
  849. .I
  850. yyy
  851. .R
  852. field of an incoming RJ message replaces
  853. the S value of the local sender and
  854. constitutes a request for retransmission to start
  855. at that sequence number.
  856. The
  857. .I
  858. yyy
  859. .R
  860. field of an incoming SRJ message selects a particular
  861. packet for retransmission.
  862. .PP
  863. The resemblance between the flow control procedure in the
  864. packet driver and that defined for X.25 is no accident.
  865. The packet driver protocol began life as an attempt at
  866. cleaning up X.25.
  867. That is why, for example,
  868. control information is uniform in length (one byte),
  869. there is no RNR message (not needed),
  870. and there is but one timeout defined
  871. in the sender.
  872. .SH
  873.     Termination
  874. .PP
  875. The CLOSE message is used to terminate communications.
  876. Software on either or both ends of the communication
  877. channel may initiate termination.
  878. In any case when one end wants to terminate it sends
  879. CLOSE messages until one is received from the other end
  880. or until a programmable limit on the number of CLOSE
  881. messages is reached.
  882. Receipt of a CLOSE message causes a CLOSE message to be sent.
  883. In the 
  884. .UX
  885. environment
  886. it also causes the SIGPIPE or
  887. `broken pipe' signal to be sent to
  888. the local process using the communication channel.
  889. .SH
  890.     Framing
  891. .PP
  892. The term
  893. .I
  894. framing
  895. .R
  896. is used to denote the technique by which the
  897. beginning and end of a message is detected
  898. in a byte stream;
  899. .I
  900. error control
  901. .R
  902. denotes the method by which transmission
  903. errors are detected.
  904. Strategies for framing and error control depend
  905. upon
  906. additional information being transmitted along
  907. with the control byte and data segment,
  908. and the choice of a particular strategy usually
  909. depends on characteristics of input/output
  910. devices and transmission media.
  911. .PP
  912. Several framing techniques are in used in support
  913. of PK protocol implementations,
  914. not all of which can be described in detail here.
  915. The technique used on asynchronous serial lines
  916. will be described.
  917. .PP
  918. A six byte
  919. framing
  920. .I
  921. envelope
  922. .R
  923. is constructed using the control byte
  924. C of a packet and five other bytes as
  925. depicted below.
  926. .in +1i
  927. <DLE><k><c0><c1><C><x>
  928. .in -1i
  929. The <DLE> symbol denotes the ASCII ctrl/P character.
  930. If the envelope is to be followed by a data segment,
  931. <k> has the value
  932. log\d2\u(size)-4;
  933. i.e. 1 \(<= k \(<= 8.
  934. If k is 9, then the envelope represents a control packet.
  935. The <c0> and <c1> bytes are the low-order and high-order
  936. bytes respectively of a 16-bit checksum of the data segment,
  937. if there is one.
  938. For control packets <c1> is zero and <c0> is the same
  939. as the control byte C.
  940. The <x> byte is the exclusive-or of <k><c0><c1><C>.
  941. Error control is accomplished by checking 
  942. a received framing envelope for compliance with the definition,
  943. and comparing a checksum function of the data segment
  944. with <c0><c1>.
  945. .PP
  946. This particular framing strategy assumes data segments
  947. are constant-sized:
  948. the `unused' bytes in a short packet are actually
  949. transmitted.
  950. This creates a certain amount of overhead which
  951. can be eliminated by a more complicated framing technique.
  952. The advantage of this strategy is that i/o
  953. devices can be programmed to take advantage of the
  954. constant-sized framing envelopes and data segments.
  955. .bp
  956. .PP
  957. The checksum calculation is displayed below as a C function.
  958. Note that the code is not truly portable because
  959. the definitions of
  960. .I short
  961. and
  962. .I char
  963. are not necessarily uniform across all machines
  964. that might support this language.
  965. This code assumes that
  966. .I short
  967. and
  968. .I char
  969. are 16 and 8-bits respectively.
  970. .PP
  971. .in +.5i
  972. .nf
  973. .ft CW
  974. .ls 1
  975. /* [Original document's version corrected to actual version] */
  976. chksum(s,n)
  977. register char *s;
  978. register n;
  979. {
  980.     register short sum;
  981.     register unsigned short t;
  982.     register short x;
  983.  
  984.     sum = -1;
  985.     x = 0;
  986.  
  987.     do {
  988.         if (sum<0) {
  989.             sum <<= 1;
  990.             sum++;
  991.         } else
  992.             sum <<= 1;
  993.         t = sum;
  994.         sum += (unsigned)*s++ & 0377;
  995.         x += sum^n;
  996.         if ((unsigned short)sum <= t) {
  997.             sum ^= x;
  998.         }
  999.     } while (--n > 0);
  1000.  
  1001.     return(sum);
  1002. }
  1003. .fi
  1004. .in -.5i
  1005. .ft R
  1006.